//
//  WarningCell.m
//  PAXY365Teacher
//
//  Created by Sunny Tong on 15/7/17.
//  Copyright (c) 2015年 新疆大德小蜜蜂通信技术有限公司 All rights reserved.
//

#import "WarningCell.h"

#import "WarningEntity.h"
#import "Common.h"

#import <SDWebImage/UIImageView+WebCache.h>

@interface WarningCell ()

@end

@implementation WarningCell
@synthesize lblTitle;
@synthesize lblDistance;
@synthesize lblName;
@synthesize newsImage;
@synthesize activityIndicator;
@synthesize lblStatus;

-(void) layoutSubviews
{
    [super layoutSubviews];
    
    //lblBGColor.backgroundColor = SubBgColor;
    
    if ([object isKindOfClass:[WarningEntity class]])
    {
        WarningEntity *data = (WarningEntity *)object;
        
        lblTitle.text = data.SafeTitle;
        lblTitle.textColor = TxtBlack;

        lblDistance.text = [NSString stringWithFormat:@"距离%@%@",data.Distance,data.Unit];
        lblDistance.textColor = TxtGray;
        
        lblName.text = [NSString stringWithFormat:@"来自%@家长",data.RealName];
        lblName.textColor = TxtGray;
        
        NSString *getStatus = data.SafeStatus;
        if ([getStatus isEqualToString:@"1"]) {
            getStatus = @"已审核";
            lblStatus.textColor = TxtBlue;
        }
        else if ([getStatus isEqualToString:@"2"]) {
            getStatus = @"已拒绝";
            lblStatus.textColor = TxtYellow;
        }
        else {
            getStatus = @"审核中";
            lblStatus.textColor = TxtBlack;
        }
        
        NSString *flagStatus = nil;
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        if (defaults){
            flagStatus = [defaults objectForKey:@"cloudin_365paxy_warning_status"];
            if ([flagStatus isEqualToString:@"1"]) {
                //隐藏状态
                lblStatus.hidden = TRUE;
                lblName.text = data.AddDate;
            }
            else{
                //显示状态
                lblStatus.hidden = FALSE;
                lblStatus.text = getStatus;
                lblName.text = data.AddDate;
            }
        }
        
        
        NSString *getHeadImageURL = data.SafeImage;
        if ([getHeadImageURL rangeOfString:@".png"].location !=NSNotFound) {
            getHeadImageURL = [getHeadImageURL stringByReplacingOccurrencesOfString:@".png" withString:@"_s.jpg"];
        }
        else if ([getHeadImageURL rangeOfString:@".jpg"].location !=NSNotFound) {
            getHeadImageURL = [getHeadImageURL stringByReplacingOccurrencesOfString:@".jpg" withString:@"_s.jpg"];
        }
        [self.newsImage setImageWithURL:[NSURL URLWithString:getHeadImageURL]
                       placeholderImage:[UIImage imageNamed:@"default_image_90_70.png"] options:SDWebImageProgressiveDownload
                               progress:^(NSInteger receivedSize, NSInteger expectedSize) {
                                   //加载图片及指示器效果
                                   if (!activityIndicator) {
                                       [newsImage addSubview:activityIndicator = [UIActivityIndicatorView.alloc initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]];
                                       activityIndicator.center = newsImage.center;
                                       [activityIndicator startAnimating];
                                   }
                               } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
                                   //清除指示器效果
                                   [activityIndicator removeFromSuperview];
                                   activityIndicator = nil;
                               }];
        //newsImage.contentMode = UIViewContentModeScaleAspectFill;
        newsImage.layer.masksToBounds = YES;
        newsImage.layer.cornerRadius = 5.0;

        
    }
}

-(void) dealloc
{
    [super dealloc];
}


@end
